package org.android;

import org.helloroad.Contact;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class ContactAddView extends Activity {
	
	private static final int ACTIVITY_CREATE = 0;
	private EditText loginToFind;
	private Button addButton;
	private Contact newContact;
	private int userId;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.contact_add);
		
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			userId = extras.getInt("userId");
			
			addButton = (Button) findViewById(R.id.Add);
			addButton.setOnClickListener(new View.OnClickListener()
			{
				public void onClick(View v) {
					loginToFind = (EditText) findViewById(R.id.LoginToFind);
					newContact = WSCommunicator.getContactInfo(loginToFind
							.getText().toString());
					WSCommunicator.addContact(userId, newContact.getId());
					goToContactList();
				}
			});
		}
	}
	
	private void goToContactList() {
		Intent i = new Intent(this, ContactListView.class);
		i.putExtra("userId", userId);
		startActivityForResult(i, ACTIVITY_CREATE);
	}
}